<?php

/**
 * This is the model class for table "{{colecao}}".
 *
 * The followings are the available columns in table '{{colecao}}':
 * @property integer $id
 * @property string $descricao
 */
class Colecao extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Colecao the static model class
	 */
	
	private static $_items=array();
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{colecao}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('descricao', 'required'),
			array('descricao', 'unique'),
			array('descricao', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, descricao', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	*/
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'text' => array(self::HAS_MANY, 'Text', 'colecao_id')
				
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'descricao' => 'Descricao',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('descricao',$this->descricao,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getColecaoOptions()
	{
		return array(
				0 => 'Male',
				1 => 'Female',
		);
	}
public static function loadItems()
	{
		self::$_items=array();
		$models=self::model()->findAll(array(			
			'order'=>'descricao',
		));
		if (!empty($models)){
			foreach($models as $model)
				self::$_items[$model->id]=$model->descricao;
		}
		return self::$_items;
			
	}
}